package com.yzc.util;

import org.springframework.core.convert.converter.Converter;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;

//将字符串转换为java.sql.Time
public class StringToTimeConverter implements Converter<String, Time>{

    private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    @Override
    public Time convert(String source) {
        try {
            return new Time(dateFormat.parse(source).getTime());
        } catch (ParseException e) {
            throw new IllegalArgumentException("Invalid time format: " + source);
        }
    }
}
